package store.lunangangster.engine.impl.entity;

public class VariableType {

  public static final String BOOLEAN_TYPE = "Boolean";

  public static final String INTEGER_TYPE = "Integer";

  public static final String FLOAT_TYPE = "Float";

  public static final String DOUBLE_TYPE = "Double";

  public static final String STRING_TYPE = "String";

  public static final String BYTES_TYPE = "Bytes";


  public static String resolveType(Object value) {
    if (isBooleanType(value)) {
      return BOOLEAN_TYPE;
    } else if (isIntegerType(value)) {
      return INTEGER_TYPE;
    } else if (isFloatType(value)) {
      return FLOAT_TYPE;
    } else if (isDoubleType(value)) {
      return DOUBLE_TYPE;
    } else if (isStringType(value)) {
      return STRING_TYPE;
    } else if (isBytesType(value)) {
      return BYTES_TYPE;
    }
    return null;
  }

  protected static boolean isBooleanType(Object value) {
    return boolean.class.isAssignableFrom(value.getClass()) || Boolean.class.isAssignableFrom(value.getClass());
  }

  protected static boolean isIntegerType(Object value) {
    return int.class.isAssignableFrom(value.getClass()) || Integer.class.isAssignableFrom(value.getClass());
  }

  protected static boolean isFloatType(Object value) {
    return float.class.isAssignableFrom(value.getClass()) || Float.class.isAssignableFrom(value.getClass());
  }

  protected static boolean isDoubleType(Object value) {
    return double.class.isAssignableFrom(value.getClass()) || Double.class.isAssignableFrom(value.getClass());
  }

  protected static boolean isStringType(Object value) {
    return String.class.isAssignableFrom(value.getClass());
  }

  protected static boolean isBytesType(Object value) {
    return byte[].class.isAssignableFrom(value.getClass());
  }
}
